<template>
  <div class="primary">
    <PersonalHeader :content="1"></PersonalHeader>

    <section class="primarymain">
      <section class="type">
        <h2 class="title"> {{$t('gailogin[0]')}}
          <p>用于账户登录</p>
        </h2>
        <ul class="contt">
          <el-form label-position="top" label-width="80px" :model="formLabelAlign" :rules="rules" ref="ruleForm" prop="name">
            <el-form-item :label="$t('gailogin[1]')" prop="old_login_pwd">
              <el-input v-model="formLabelAlign.old_login_pwd" :placeholder="$t('gailogin[2]')" show-password></el-input>
            </el-form-item>
            <el-form-item :label="$t('gailogin[3]')" prop="new_login_pwd">
              <el-input v-model="formLabelAlign.new_login_pwd" :placeholder="$t('gailogin[4]')" show-password></el-input>
            </el-form-item>
            <el-form-item :label="$t('mobile[6]')" prop="new_login_pwd_confirmation">
              <el-input v-model="formLabelAlign.new_login_pwd_confirmation" :placeholder="$t('regz[3]')" show-password></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleSubmit" :loading="loading">{{$t('senior[8]')}}</el-button>
            </el-form-item>
          </el-form>
        </ul>
      </section>
    </section>
  </div>
</template>

<script>
import { resetPassword } from '@/api/securitycenter'
import PersonalHeader from "_dom/personalheader";
import { Passwordencryption } from "@/libs/util";
import md5 from 'md5'
export default {
  name: 'syloginpassword',
  data() {
    var validatePass1 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error(this.$t('gailogin[2]')));
      } else if (this.$public.pwds(value)) {
        callback();
      } else {
        callback(new Error(this.$t('reg[13]')));
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error(this.$t('zijin[6]')));
      } else if (this.$public.pwds(value)) {
        callback();
      } else {
        callback(new Error(this.$t('reg[13]')));
      }
    };
    var validatePass3 = (rule, value, callback) => {
      if (value === '') {
        callback(new Error(this.$t('zijin[7]')));
      } else if (value !== this.formLabelAlign.new_login_pwd) {
        callback(new Error(this.$t('mobile[14]')));
      } else {
        callback();
      }
    };
    return {
      formLabelAlign: {
        old_login_pwd: "",
        new_login_pwd: "",
        new_login_pwd_confirmation: "",
      },
      loading: false,
      rules: {
        old_login_pwd: [
          { validator: validatePass1, trigger: 'blur' }
        ],
        new_login_pwd: [
          { validator: validatePass2, trigger: 'blur' }
        ],
        new_login_pwd_confirmation: [
          { validator: validatePass3, trigger: 'blur' }
        ],
      },
    }
  },
  methods: {
    handleSubmit() {//修改登录密码
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.loading = true;
          resetPassword(Passwordencryption(this.formLabelAlign)).then(res => {
            this.loading = false;
            this.$message({
              message: this.$t('gailogin[6]'),
              type: 'success'
            });
            localStorage.clear();
            setTimeout(() => {
              this.$router.push({ path: "/login" });
            }, 800);
          }).catch(err => {

          });
        }
      })
    }
  },
  created() {

  },
  components: {
    PersonalHeader
  },
}
</script>

